package paa.simulator;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.Set;

import paa.crawlers.delicious.Crawler;
import paa.simulator.grafo.PessoaVertex;
import paa.simulator.grafo.simple.ConnectivityCounter;
import paa.simulator.grafo.simple.UndirectedSimpleGraph;

public class ConnectedFinder {

	public static void main(String[] args) throws Exception {
		if (args == null || args.length < 1) {
			System.err.println("usage: java " + Crawler.class + " <graph object>");
			System.exit(1);
		}
		
		//Loading
		System.out.println("Loading Graph Object");
		ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(args[0])));
		UndirectedSimpleGraph<PessoaVertex> graph = (UndirectedSimpleGraph<PessoaVertex>) ois.readObject();
		ois.close();
		
		ConnectivityCounter cc = new ConnectivityCounter();
		Set<Set<PessoaVertex>> findConnectedSets = cc.findConnectedSets(graph);
		
		int max = 0;
		Set<PessoaVertex> maxSet = null;
		for (Set<PessoaVertex> set : findConnectedSets) {
			int size = set.size();
			
			if (size > max) {
				max = size;
				maxSet = set;
			}
			
			System.out.println(size);
		}
		
		for (PessoaVertex pv : maxSet) {
			System.out.println(pv);
		}
	}
	
}
